package cn.com.lms.app.api.index;


import cn.com.lms.app.api.index.vo.ToDisposeVO;
import cn.com.lms.business.core.util.SystemUserUtil;
import cn.com.lms.business.exam.service.ExerciseService;
import com.bnzj.core.persistence.query.CompareExpression;
import com.bnzj.core.persistence.query.CompareType;
import com.bnzj.core.persistence.query.IExpression;

import com.bnzj.core.persistence.query.QueryHelpBean;
import com.bnzj.core.rest.ResponseResult;
import com.bnzj.core.webmvc.util.WebMvcUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * @author zhangzhenjiang
 * @createDate 2020/3/21
 * @description
 */
@Tag(name = "首页", description = "App首页")
@RestController
@RequestMapping("/app/api/index")
public class IndexApi {

    @Autowired
    ExerciseService exerciseService;



    @Operation(summary = "代办事项", description = "代办事项", parameters = {
            @Parameter(name = "type", description = "分类 1-学习计划 2-练习", allowEmptyValue = true,
                    allowReserved = true, schema = @Schema(implementation = Integer.class, description = "type")),
            @Parameter(name = "limit", description = "分页大小", allowEmptyValue = true, allowReserved = true, schema = @Schema(type = "int", description = "分页大小")),
            @Parameter(name = "offset", description = "页码", allowEmptyValue = true, allowReserved = true, schema = @Schema(type = "int", description = "页码")),
    })
    @GetMapping(value = "/toDispose")
    public ResponseResult<Page<ToDisposeVO>> getToDisposeVOPage(HttpServletRequest request) {
        Pageable pageable = WebMvcUtils.initPage(request, Sort.by(Sort.Direction.DESC, "tem.dataTime"));
        Long userId=SystemUserUtil.getCurrentUser()!=null?SystemUserUtil.getCurrentUser().getId():10000000L;

        QueryHelpBean queryHelpBean = ExerciseService.getToDisposeQueryHelpBean(userId);
        queryHelpBean.setPageable(pageable);
        //试卷名称，模糊搜索
        IExpression andCondition1 = CompareExpression.build("tem.type", CompareType.equal, request.getParameter("type"));
        queryHelpBean.addWhere(andCondition1);
        Page<ToDisposeVO> all = exerciseService.findAll(queryHelpBean);
        return ResponseResult.success(all);
    }



}
